package storage;
import java.io.*;
import java.net.*;
import common.*;

public class MeClient{
/*	private String ip;
	private int port;
	private String in_msg;
	BufferedReader key_input;
	
	private String ME_SCHEME;
	private int N_LOCAL_NODES;
	
	public MeClient( String new_ip, int new_port ) throws IOException{
		ip = new_ip;
		port = new_port;

		// create a socket
		System.out.print( "Connecting to the server... (Press Ctrl-C to break)" );
		Socket tcpSocket = getSocket();
		System.out.println( "\n[connected] Host IP = " + ip );
		OutputStream os_socket = tcpSocket.getOutputStream();	// write to socket
		InputStream is_socket = tcpSocket.getInputStream();		// read from socket
  
		BufferedWriter buffer_wr = new BufferedWriter( new OutputStreamWriter( os_socket ) );
		BufferedReader buffer_rd = new BufferedReader( new InputStreamReader( is_socket ) );
		
		// Handshake for Simulation Setting
		in_msg = buffer_rd.readLine();
		print_log( in_msg );
		if( !in_msg.equals( Protocol.SIMUL_SET ) ){
			print_log( "Unknown handshaking steps. Try again.", Protocol.STDERR );

			// clean up
			key_input.close();
			buffer_wr.close();
			buffer_rd.close();
			
			// Connection close
			tcpSocket.close();

			System.exit( 0 );
		}else{
			buffer_wr.write( Protocol.SIMUL_SET_OK + System.getProperty( "line.separator" ) );
			buffer_wr.flush();
		}
		
		// Simulation Setting
		System.out.print( "Configuration..." );
		in_msg = buffer_rd.readLine();
		System.out.print( "\n" + in_msg );
		key_input = new BufferedReader( new InputStreamReader( System.in ) );
		in_msg = key_input.readLine();
		in_msg += System.getProperty( "line.separator" );
		buffer_wr.write( in_msg );
		buffer_wr.flush();
		
		// Simulation Setting confirm
		in_msg = buffer_rd.readLine();
		if( in_msg.equals( Protocol.PARAM_TOKENLESS ) || in_msg.equals( Protocol.PARAM_TOKEN ) ){
			ME_SCHEME = in_msg;
			System.out.println( "\n" + in_msg );
		}
		
		// node distribution (NOT load distribution)
		in_msg = buffer_rd.readLine();
		if( !Utils.isNumber( in_msg ) ){
			print_log( "Unknown handshaking steps. Try again.", Protocol.STDERR );

			// clean up
			key_input.close();
			buffer_wr.close();
			buffer_rd.close();
			
			// Connection close
			tcpSocket.close();

			System.exit( 0 );
		}else{
			N_LOCAL_NODES = Integer.parseInt( in_msg );
		}
		
		buffer_wr.write( Protocol.SIMUL_READY + System.getProperty( "line.separator" ) );
		buffer_wr.flush();

		// network.start();	// -- create a network (which has a routing table and methods). pass the connection to the network.
		
		// running
		if( ME_SCHEME.equals( Protocol.PARAM_TOKENLESS ) ){
			// Ricart-Agrawala's algorithm
			System.out.println( "[Simulation] starts: Tokenless (Ricart-Agrawala)..." );
			
			// init&run threads
			System.out.println( "[Init] " + N_LOCAL_NODES + " nodes." );
			
			
//			for( int i = 0; i < Config.NUMBER_OF_NODES; i++ ){
//				nodes.add( new centralized.Node( network ) );
//				for( int j = 0; j < 5000000; j++ );
//				nodes.get( i ).start();
//			}
//			
//			Runnable input_box = new centralized.MsgInjector( network );
//			Thread shell = new Thread( input_box );
//			
//			shell.start();

			
			
		}else if( ME_SCHEME.equals( Protocol.PARAM_TOKEN ) ){
			// Raymond's algorithm
			System.out.println( "[Simulation] starts: Token-based (Raymond)..." );
			
			// init&run threads
			System.out.println( "[Init] " + N_LOCAL_NODES + " nodes." );
			
			
			
		}//end-of-if( ME_SCHEME... )
		
		// send
		//bufferW.write( str );
		//bufferW.flush();
		//str = bufferR.readLine();
		//System.out.println( "Echo Result: " + str );
		
		// clean up
		key_input.close();
		buffer_wr.close();
		buffer_rd.close();
		
		// Connection close
		tcpSocket.close();
	}//end-of-MeClient()
	
	
	// TCP connector
	public Socket getSocket(){
		Socket tcpSocket = null;
		
		try{
			tcpSocket = new Socket( ip, port );
		}catch( IOException e ){
			e.printStackTrace();
			System.exit( 0 );
		}
		
		return tcpSocket;
	}//end-of-getSocket()
	
	
	// dump wrapper
	public void print_log( String log ){
		print_log( log, Protocol.STDOUT );
	}
	
	public void print_log( String log, byte target ){
		if( !Config.VERBOSE )
			return;
		
		if( target == Protocol.STDOUT ){
			//System.out.print( "[MSG|" + pid + ":" + Utils.ipToString( ip ) + "(" + localtime_s + ")] " );
			System.out.println( log );
		}else if( target == Protocol.STDERR ){
			//System.err.print( "[ERR|" + pid + ":" + Utils.ipToString( ip ) + "(" + localtime_s + ")] " );
			System.err.println( log );
		}
	}

	
	public static void main( String[] args ) throws IOException{
		new MeClient( "localhost", Config.PORT_NO );
	}//end-of-main()
*/
}//end-of-class
